package cn.sc.summer.calculate.service.impl;

import cn.hutool.core.util.StrUtil;
import cn.sc.summer.calculate.form.GetLogPageForm;
import cn.sc.summer.calculate.mapper.GatewayLogMapper;
import cn.sc.summer.calculate.service.GatewayLogService;
import cn.sc.summer.calculate.vo.GatewayLogVO;
import cn.sc.summer.constant.model.PageResult;
import cn.sc.summer.mybatis.annotation.dynamicdatasource.DataSource;
import cn.sc.summer.mybatis.enums.DataSourceEnum;
import cn.sc.summer.rabbitmq.po.GatewayLog;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 类名：网关访问日志操作业务层
 *
 * @author a-xin
 * @date 2024/2/7 16:43
 */
@Slf4j
@Service
public class GatewayLogServiceImpl implements GatewayLogService {

    @Resource
    private GatewayLogMapper gatewayLogMapper;

    /**
     * 分页获取网关访问日志
     *
     * @param form 分页请求表单
     * @return 网关日志
     */
    @Override
    @DataSource(DataSourceEnum.POST_GRE_SQL)
    public PageResult<GatewayLogVO> getGatewayLog(GetLogPageForm form) {
        return gatewayLogMapper.selectPage(form, new LambdaQueryWrapper<GatewayLog>()
                        .eq(StrUtil.isNotBlank(form.getServiceName()), GatewayLog::getApiServiceName, form.getServiceName()),
                GatewayLogVO.class);
    }

}
